package com.jackeys.piaems.dao.impl;

import com.jackeys.piaems.dao.PaymentDao;
import com.jackeys.piaems.dao.mapper.PaymentMapper;
import com.jackeys.piaems.dto.PaymentDetailDto;
import com.jackeys.piaems.entity.Payment;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * @ClassName: PaymentDaoImpl
 * @Description: 账单接口实现类
 * @Author: Jackeys
 * @Date: 2021-06-17 20:10
 * @Version: 1.0
 */
@Repository
public class PaymentDaoImpl implements PaymentDao {

    @Autowired
    private PaymentMapper paymentMapper;

    /**
     * @Name: insertPayment
     * @Description: 添加账单到数据库，实现添加账单的功能
     * @Param: [userId, categoryId, date, cost, remark, flag]
     * @return: boolean
     * @Author: Jackeys
     * @Date: 2021/6/17 20:11
     * @Version: 1.0
     */
    @Override
    public Boolean insertPayment(Long userId, Long categoryId, Date date, Float cost, String remark, Integer flag) {
        return paymentMapper.insertPayment(userId, categoryId, date, cost, remark, flag);
    }

    /**
     * @Name: deletePayment
     * @Description: 在数据库中删除账单，实现删除订单的功能
     * @Param: [id]
     * @return: boolean
     * @Author: Jackeys
     * @Date: 2021/6/17 20:12
     * @Version: 1.0
     */
    @Override
    public Boolean deletePayment(Long id) {
        return paymentMapper.deletePayment(id);
    }

    /**
     * @Name: updatePayment
     * @Description: 更新数据库账单，实现修改账单的功能
     * @Param: [id, categoryId, cost, remark, flag]
     * @return: boolean
     * @Author: Jackeys
     * @Date: 2021/6/17 20:13
     * @Version: 1.0
     */
    @Override
    public Boolean updatePayment(Long id, Long categoryId, Float cost, String remark, Integer flag) {
        return paymentMapper.updatePayment(id, categoryId, cost, remark, flag);
    }

    /**
     * @Name: selectPaymentsByDate
     * @Description: 通过日期查询账单，实现查询账单详情的功能
     * @Param: [userId, date]
     * @return: java.util.List<com.jackeys.piaems.entity.Payment>
     * @Author: Jackeys
     * @Date: 2021/6/17 20:14
     * @Version: 1.0
     */
    @Override
    public List<PaymentDetailDto> selectPaymentsByDate(Long userId, Date date, Integer flag) {
        return paymentMapper.selectPaymentsByDate(userId, date,flag);
    }


    /**
     * @Name: selectInAndOutSum
     * @Description: 查询数据库，计算支出与收入
     * @Param: [userId, flag]
     * @return: java.lang.Float
     * @Author: Jackeys
     * @Date: 2021/6/26 11:01
     * @Version: 1.0
     */
    @Override
    public Float selectInAndOutSum(Long userId, Integer flag) {
        return paymentMapper.selectInAndOutSum(userId, flag);
    }

    /**
     * @Name: selectTotalPaymentList
     * @Description: 查询数据账单的大概，实现概述功能
     * @Param: [userId]
     * @return: java.util.List<com.jackeys.piaems.entity.Payment>
     * @Author: Jackeys
     * @Date: 2021/6/26 11:26
     * @Version: 1.0
     */
    @Override
    public List<Payment> selectTotalPaymentList(Long userId,Integer start,Integer size,Integer flag) {
        return paymentMapper.selectTotalPaymentList(userId,start,size,flag);
    }

    /**
    * @Name: selectCntByTotal
    * @Description: 查询用户账单总览的数量
    * @Param: [userId]
    * @return: java.lang.Integer
    * @Author: Jackeys
    * @Date: 2021/6/26 13:29
    * @Version: 1.0
    */
    @Override
    public Integer selectCntByTotal(Long userId,Integer flag) {
        return paymentMapper.selectCntByTotal(userId,flag);
    }

    /**
    * @Name: selectAllPayment
    * @Description: 返回前端涂图表信息，实现展示图表的功能
    * @Param: []
    * @return: java.util.List<com.jackeys.piaems.entity.Payment>
    * @Author: Jackeys
    * @Date: 2021/6/28 22:33
    * @Version: 1.0
    */
    @Override
    public List<Payment> selectAllPayment(Long userId, Integer flag) {
        return paymentMapper.selectAllPayment(userId,flag);
    }


}
